﻿using Awsc.DataAcquisitionSys.Core.Models.POCO;
using Awsc.DataAcquisitionSys.Core.Services.MissionManagement;
using Microsoft.AspNetCore.Mvc;

namespace Awsc.DataAcquisitionSys.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MissionsController : ControllerBase
    {
        private readonly IMissionService missionService;

        public MissionsController(IMissionService missionService)
        {
            this.missionService = missionService;
        }
        [HttpGet]
        public async Task<IEnumerable<Mission>> GetAllMissions()
        {
            return  await missionService.GetAllMssionsAsync();
        }

        [HttpPost]
        public async Task<Mission> CreateMission([FromBody]Mission mission)
        {
            var re = await missionService.CreateMissionAsync(mission);
            return mission;
        }
        [HttpPost("{missionId}")]
        public async Task<Mission> UpdateMission([FromRoute]int missionId, [FromBody] Mission mission)
        {
            var re = await missionService.UpdateMissionAsync(missionId,mission);
            return mission;
        }



        [HttpGet("{missionId}")]
        public async Task<Mission> GetMission([FromRoute]int missionId)
        {
            return await missionService.GetMissionAsync(missionId);
        }
        [HttpGet("{missionId}/start")]
        public async Task StartMission(int missionId)
        {
             await missionService.StartMissionAsync(missionId);
        }
        [HttpGet("{missionId}/stop")]
        public async Task StopMission(int missionId)
        {
            await missionService.FinishMissionAsync(missionId);
        }

    }
}
